package com.lzb.randomturntable.dialog;

import android.content.Context;
import android.view.Gravity;
import android.view.View;

import androidx.annotation.NonNull;

import com.lzb.basic.dialog.BaseSmartDialog;
import com.lzb.randomturntable.R;
import com.lzb.randomturntable.databinding.DialogBombBinding;


public class BombDialog extends BaseSmartDialog<DialogBombBinding> implements View.OnClickListener {

    private String confirmText = null;

    public void setConfirmText(String text) {
        this.confirmText = text;
        if (mDataBinding != null && mDataBinding.tvConfirm != null) {
            mDataBinding.tvConfirm.setText(text);
        }
    }

    public BombDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected boolean canceledOnTouchOutside() {
        return true;
    }

    @Override
    protected int getGravity() {
        return Gravity.CENTER;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_bomb;
    }

    @Override
    protected void initView(View view) {
        mDataBinding.tvConfirm.setOnClickListener(this);
        mDataBinding.ivCancel.setOnClickListener(this);
        
        // 如果有自定义确认按钮文字，则设置
        if (confirmText != null) {
            mDataBinding.tvConfirm.setText(confirmText);
        }
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.ivCancel) {
            dismiss();
        } else if (id == R.id.tvConfirm) {
            dismiss();
            if (listener != null) {
                listener.clickConfirm();
            }
        }
    }

    private Ilistener listener;

    public void setListener(Ilistener listener) {
        this.listener = listener;
    }

    public interface Ilistener {
        void clickConfirm();
    }
}
